home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Extensions / Imaging / Tk / booster.txt next >
Encoding:
Text File  |  2000-06-23  |  3.8 KB  |  109 lines

  1. ====================================================================
  2. The Photoimage Booster Patch (for Windows 95/NT)
  3. ====================================================================
  4.  
  5.   This patch kit boosts performance for 16/24-bit displays.  The
  6. first patch is required on Tk 4.2 (where it fixes the problems for
  7. 16-bit displays) and later versions, with the exception for Tk 8.0b1
  8. where Sun added something similar themselves, only to remove it in
  9. 8.0b2.  By installing both patches, Tk's PhotoImage handling becomes
  10. much faster on both 16-bit and 24-bit displays.  The patch has been
  11. tested with Tk 4.2 and 8.0.
  12.  
  13.   Here's a benchmark, made with a sample program which loads two
  14. 512x512 greyscale PGM's, and two 512x512 colour PPM's, and displays
  15. each of them in a separate toplevel windows.  Tcl/Tk was compiled
  16. with Visual C 4.0, and run on a P100 under Win95.  Image load times
  17. are not included in the timings:
  18.  
  19.             8-bit        16-bit        24-bit
  20. --------------------------------------------------------------------
  21. 1. original 4.2 code    5.52 s        8.57 s        3.79 s
  22. 2. booster patch    5.49 s        1.87 s        1.82 s
  23.  
  24.    speedup        None        4.6x        2.1x
  25.  
  26. ====================================================================
  27.  
  28. Here's the patches:
  29.  
  30. 1. For portability and speed, the best thing under Windows is to
  31. treat 16-bit displays as if they were 24-bit. The Windows device
  32. drivers take care of the rest.
  33.  
  34.    ----------------------------------------------------------------
  35.    If you have Tk 4.1 or Tk 8.0b1, you don't have to apply this
  36.    patch!  It only applies to Tk 4.2, Tk 8.0a[12] and Tk 8.0b2.
  37.    ----------------------------------------------------------------
  38.  
  39. In win/tkWinImage.c, change the following line in XCreateImage:
  40.  
  41.     imagePtr->bits_per_pixel = depth;
  42.  
  43. to
  44.  
  45. /* ==================================================================== */
  46. /* The tk photo image booster patch -- patch section 1                  */
  47. /* ==================================================================== */
  48.  
  49.     if (visual->class == TrueColor)
  50.     /* true colour is stored as 3 bytes: (blue, green, red) */
  51.     imagePtr->bits_per_pixel = 24;
  52.     else
  53.     imagePtr->bits_per_pixel = depth;
  54.  
  55. /* ==================================================================== */
  56.  
  57.  
  58. 2. The DitherInstance implementation is not good.  It's especially
  59. bad on highend truecolour displays.  IMO, it should be rewritten from
  60. scratch (some other day...).
  61.  
  62.   Anyway, the following band-aid makes the situation a little bit
  63. better under Windows.  This hack trades some marginal quality (no
  64. dithering on 16-bit displays) for a dramatic performance boost.
  65. Requires patch 1, unless you're using Tk 4.1 or Tk 8.0b1.
  66.  
  67. In generic/tkImgPhoto.c, add the #ifdef section to the DitherInstance
  68. function:
  69.  
  70.     for (; height > 0; height -= nLines) {
  71.     if (nLines > height) {
  72.         nLines = height;
  73.     }
  74.     dstLinePtr = (unsigned char *) imagePtr->data;
  75.     yEnd = yStart + nLines;
  76.  
  77. /* ==================================================================== */
  78. /* The tk photo image booster patch -- patch section 2                  */
  79. /* ==================================================================== */
  80.  
  81. #ifdef __WIN32__
  82.     if (colorPtr->visualInfo.class == TrueColor
  83.         && instancePtr->gamma == 1.0) {
  84.         /* Windows hicolor/truecolor booster */
  85.         for (y = yStart; y < yEnd; ++y) {
  86.         destBytePtr = dstLinePtr;
  87.         srcPtr = srcLinePtr;
  88.         for (x = xStart; x < xEnd; ++x) {
  89.             destBytePtr[0] = srcPtr[2];
  90.             destBytePtr[1] = srcPtr[1];
  91.             destBytePtr[2] = srcPtr[0];
  92.             destBytePtr += 3; srcPtr += 3;
  93.         }
  94.         srcLinePtr += lineLength;
  95.         dstLinePtr += bytesPerLine;
  96.         }
  97.     } else
  98. #endif
  99.  
  100. /* ==================================================================== */
  101.  
  102.     for (y = yStart; y < yEnd; ++y) {
  103.         srcPtr = srcLinePtr;
  104.         errPtr = errLinePtr;
  105.         destBytePtr = dstLinePtr;
  106.  
  107. ====================================================================
  108. last updated: 97-07-03/fl
  109.